<?php
namespace app\api\controller;
/**
 * @Author: 刘洪
 * @Date:   2019-03-30 09:49:00
 * @Last Modified by:   user
 * @Last Modified time: 2019-04-04 15:11:22
 */
use think\Controller;
use think\Db;
/**
 * 
 */
class ApiAnswerController extends Controller
{
	public function insert()
	{
		$data=$this->request->param();
		$insert=[];
		//正确答案
		$answer=['C','D','B','A','B','D','A','C','D','C','A','B','A','A','B','A','B','B','A','A'];
		$ds=[];
		foreach ($data['answers'] as $key => $value) {
			$d=[];
			$d['id']=$value['id']+1;
			$d['answer']=$value['answer'];
			$d['right']=$answer[$value['id']];
			$ds[]=$d;
		}
		$insert['remark']=$data['remark'];
		$insert['answer']=json_encode($ds,JSON_UNESCAPED_UNICODE);
		$res = Db::name('answer_sheet')->insertGetId($insert);
		if($res){
			return 1;
		}
		return 0;
	}
}